package com.xiyin.methods;

import com.xiyin.entity.UserSqlInjector;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author 徐开航
 */
public class TblUserSqlProvider {

    public String dynamicSelect(final UserSqlInjector UserSqlInjector) {
        return new SQL() {
            {
                SELECT("id, user_name, age, email");
                FROM("user_sql_injector");
                if (UserSqlInjector.getUserName()!= null && !UserSqlInjector.getUserName().isEmpty()) {
                    WHERE("user_name LIKE CONCAT('%', #{userName}, '%')");
                }
                if (UserSqlInjector.getAge() != null) {
                    WHERE("age > #{age}");
                }
            }
        }.toString();
    }
}
